<template>
  <div class="callback-loading">
    <van-loading type="spinner" size="24px">处理中...</van-loading>
  </div>
</template>

<script setup>
import { onMounted } from 'vue'
import { useRoute, useRouter } from 'vue-router'
import { useAuthStore } from '@/stores/auth'
import { showToast } from 'vant'

const route = useRoute()
const router = useRouter()
const authStore = useAuthStore()

onMounted(async () => {
  if (import.meta.env.MODE === 'development') {  // 修改这里
    await authStore.handleWxCallback()
    return;
  }else{
    const { code } = route.query
    if (!code) {
      showToast('授权失败')
      router.push('/')
      return
    }
    const success = await authStore.handleWxCallback(code)
  }
  if (success) {
    router.push('/doctor/login')
  } else {
    showToast('授权失败')
    router.push('/')
  }
})
</script>

<style scoped>
.callback-loading {
  height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
}
</style> 